import * as echarts from 'echarts';
import React, { useEffect, useRef } from 'react';

const EchartsComponent = ({ title,array }) => {
    const chartRef = useRef(null);

    useEffect(() => {
        const chartDom = chartRef.current;
        const myChart = echarts.init(chartDom);
        const option = {
            title: {
                text: title
            },
            xAxis: {
                type: 'category',
                data: ['Vue', 'angular', 'react']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data: array,
                    type: 'bar'
                }
            ]
        };

        option && myChart.setOption(option);
    }, []);

    return (
        <div>
            <div ref={chartRef} style={{ width: '600px', height: '400px' }}></div>
        </div>
    );
};

export default EchartsComponent;
